//
//  MMWaitingViewController.m
//  MemeMaker
//
//  Created by dangthan on 8/13/13.
//  Copyright (c) 2013 soyo. All rights reserved.
//

#import "MMWaitingViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface MMWaitingViewController ()

@end

@implementation MMWaitingViewController
@synthesize indicator = _indicator, message = _message, cornerRoundedView = _cornerRoundedView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.cornerRoundedView.layer setCornerRadius:10];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) start {
    [_indicator startAnimating];
}

- (void) stop {
    [_indicator stopAnimating];
}

- (void) startWithMessage:(NSString *)message {
    _message.text = message;
    [_indicator startAnimating];
}

- (void) hide {
    [self.view removeFromSuperview];
}

- (void) disappear {
    [UIView beginAnimations:@"View Hide" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    
    CGSize targetSize = CGSizeMake(320, 320);
    self.cornerRoundedView.frame = CGRectMake((self.view.frame.size.width - targetSize.width)/2,
                                              (self.view.frame.size.height - targetSize.height)/2,
                                              targetSize.width,
                                              targetSize.height);
    self.view.alpha = 0.01f;
    [UIView commitAnimations];
    [NSTimer scheduledTimerWithTimeInterval:0.3f target:self selector:@selector(hide) userInfo:nil repeats:NO];

}

@end
